import urlConfig from "../config/config.js"
export default {
	loginApi(phone, password) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/login/login",
				method: "POST",
				data: {mobile: phone, password: password},
				header:{token: Math.random()},
				success: (res) => {
					resolve(res.data)
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	findSuccessStar(token) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/cat/mycat?page=1&status=2",
				method: "GET",
				header:{token: token},
				success: (res) => {
					if (res.data.code === 0 && res.data.data.data) {
						resolve(res.data.data)
					}
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	getNowTimeApi(token) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/user/info",
				method: "GET",
				header:{token: token},
				success: (res) => {
					resolve(Number(res.data.time * 1000))
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	getUserInfoApi(token) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/user/info",
				method: "GET",
				header:{token: token},
				success: (res) => {
					if (res.data.code === 0) {
						resolve(res.data.data)
					} else {
						this.$message.error(res.data.msg)
					}
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	getConfigJson() {
		return new Promise((resolve, reject) => {
			uni.request({
				url: "https://autostar.coding.net/p/macList/d/macList/git/raw/master/deviceList?t=" + Math.random(),
				method: "GET",
				success: (res) => {
					resolve(res)
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	getPriceJson() {
		return new Promise((resolve, reject) => {
			uni.request({
				url: "https://autostar.coding.net/p/macList/d/macList/git/raw/master/mobilePrice.json?t=" + Math.random(),
				method: "GET",
				success: (res) => {
					resolve(res)
				},
				fail(err) {
					reject(err)
				}
			})
		})
	},
	getStarInfoApi(token) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/cat/cat",
				method: "GET",
				header:{token: token},
				success: (res) => {
					resolve(res.data)
				},
				fail(err) {
					console.log(44444)
					reject("获取星座信息失败")
				}
			})
		})
	},
	getApi(id, token) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/cat/buy",
				method: "POST",
				data: {cat_id: id},
				header:{token: token},
				success: (res) => {
					resolve(res)
				},
				fail(err) {
					reject("失败")
				}
			})
		})
	},
	getSuccessStar(token) {
		return new Promise((resolve, reject) => {
			uni.request({
				url: urlConfig.baseUrl + "/cat/mycat?page=1&status=2",
				method: "GET",
				header:{token: token},
				success: (res) => {
					if (res.data.code === 0 && res.data.data.data) {
						resolve(res)
					}
				},
				fail(err) {
					reject("失败")
				}
			})
		})
	}

}
